using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Scenario_Editor.WR2TerrainLoader
{
    class Object
    {
        ObjectName name;
        int     objectPropertieID;
        float   positionX;
        float   positionY;
        float   positionZ;
        float   keineAhnung;
        float   size;
        float   cosisnus;
        byte[]  keineAhnung2 = new byte[4];// war 0
        float   sinus;
        float   ausrichtung1;// 0 vieleicht keine Ahnung
        float   ausrichtung2;// 1
        float   ausrichtung3;// 0
        float   negativerSinus;
        byte[]  keineAhnung3 = new byte[4];
        float   negativerCosinus;
        byte[]  keineAhnung4  = new byte[8];

        internal static Object FromStream(BinaryReader br)
        {
            Object obj = new Object();
            obj.name = ObjectName.LoadFromStream(br);
            obj.objectPropertieID = br.ReadInt32();
            obj.positionX = br.ReadSingle();
            obj.positionY = br.ReadSingle();
            obj.positionZ = br.ReadSingle();
            obj.keineAhnung = br.ReadSingle();
            obj.size = br.ReadSingle();
            obj.cosisnus = br.ReadSingle();
            obj.keineAhnung2 = br.ReadBytes(4); ;// war 0
            obj.sinus = br.ReadSingle();
            obj.ausrichtung1 = br.ReadSingle();// 0 vieleicht keine Ahnung
            obj.ausrichtung2 = br.ReadSingle();// 1
            obj.ausrichtung3 = br.ReadSingle();// 0
            obj.negativerSinus = br.ReadSingle();
            obj.keineAhnung3 = br.ReadBytes(4);
            obj.negativerCosinus = br.ReadSingle();
            obj.keineAhnung4 = br.ReadBytes(8);

            return obj;            
        }

        internal void Save(BinaryWriter bw)
        {
            this.name.Save(bw); //obj.name = ObjectName.LoadFromStream(br);
            bw.Write(this.objectPropertieID);//obj.objectPropertieID = br.ReadInt32();
            bw.Write(this.positionX);//obj.positionX = br.ReadSingle();
            bw.Write(this.positionY);//obj.positionY = br.ReadSingle();
            bw.Write(this.positionZ);//obj.positionZ = br.ReadSingle();
            bw.Write(this.keineAhnung);//obj.keineAhnung = br.ReadSingle();
            bw.Write(this.size);//obj.size = br.ReadSingle();
            bw.Write(this.cosisnus); //obj.cosisnus = br.ReadSingle();
            bw.Write(this.keineAhnung2);//obj.keineAhnung2 = br.ReadBytes(4); ;// war 0
            bw.Write(this.sinus); //obj.sinus = br.ReadSingle();
            bw.Write(this.ausrichtung1);   //obj.ausrichtung1 = br.ReadSingle();// 0 vieleicht keine Ahnung
            bw.Write(this.ausrichtung2); //obj.ausrichtung2 = br.ReadSingle();// 1
            bw.Write(this.ausrichtung3); //obj.ausrichtung3 = br.ReadSingle();// 0
            bw.Write(this.negativerSinus); //obj.negativerSinus = br.ReadSingle();
            bw.Write(this.keineAhnung3);//obj.keineAhnung3 = br.ReadBytes(4);
            bw.Write(this.negativerCosinus); //obj.negativerCosinus = br.ReadSingle();
            bw.Write(this.keineAhnung4);//obj.keineAhnung4 = br.ReadBytes(8);
        }
    }
}
